package kr.hkit.androidcomplete03.ch26;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.widget.ListView;

public class ProductListTest extends Activity {
	ProductDBHelper mHelper;
	Cursor cursor;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.productlist);

		mHelper = new ProductDBHelper(this);
		
		SQLiteDatabase db = mHelper.getWritableDatabase();

		cursor = db.rawQuery("select * from product", null);
		startManagingCursor(cursor);

		SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
				android.R.layout.simple_list_item_2, cursor, new String[] {
						"name", "price" }, new int[] { android.R.id.text1,
						android.R.id.text2 }, SimpleCursorAdapter.NO_SELECTION);
		ListView list = (ListView) findViewById(R.id.list);
		list.setAdapter(adapter);
	}
}
